package com.gzcss.gulimall.product.web;


import com.gzcss.gulimall.product.entity.CategoryEntity;
import com.gzcss.gulimall.product.service.CategoryService;
import com.gzcss.gulimall.product.vo.webVo.catalogL2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class indexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","index.html","index"})
    public String indexPage(Model model){

        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Category();

        model.addAttribute("category",categoryEntityList);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<catalogL2Vo>> getCatalogJson(){

        Map<String, List<catalogL2Vo>> catalogmap = categoryService.getCatalogl2();

        return catalogmap;
    }

}
